<!DOCTYPE html >
<ui:composition template="/template_clear.xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:c="http://java.sun.com/jsp/jstl/core">
    <c:if test="#{not userController.loggedIn}">
        <script>
            window.location.href = "./login.bio";
        </script>
    </c:if>
    <ui:define name="title">
        <h:outputText value="Home"/>
    </ui:define>
    <ui:define name="body" class="body">
        <div class="visual">
            <div class="visual-block">
                <h2>BioDesk</h2>
            </div>
        </div>

        <h:form id="page"  >
            <p:growl id="growl" showDetail="true" life="3000" />
            <p:panel header="Welcome #{userController.loggedUser.userLogin}"  styleClass="form"  >
                <c:if test="#{not userController.loggedUser.userLive}">
                    <h:graphicImage  value="resources/images/syscon/ops2.png" />
                    <h:outputText  value=" Your account was successfully created, but is still pending of activation, please try again later" styleClass="engraved"/>
                    <br/>
                </c:if>

                <c:if test="#{userController.allowedGroups('4') and userController.loggedUser.userId != 1}">
                    <h:graphicImage  value="resources/images/syscon/ops2.png" />
                    <h:outputText  value=" Your account is set as GUEST, you can only view the ongoing projects " styleClass="engraved"/>
                    <br/>
                </c:if>

                <c:if test="#{userController.allowedGroups('2')}">
                    <div onclick="dlg1.show();"  class="menu_item" >
                        <h:graphicImage  value="resources/images/syscon/user_control.png" />
                        <br/>
                        <h:outputText  value="Users"/>
                    </div>

                    <h:commandLink action="#{projectController.prepareCreate()}" immediate="true"  >
                        <div class="menu_item">
                            <h:graphicImage  value="resources/images/syscon/new_proj.png"  />
                            <br/>
                            <h:outputText  value="New Project"/>
                        </div>
                    </h:commandLink>

                    <h:commandLink action="/project/List" immediate="true"  >
                        <div class="menu_item" >
                            <h:graphicImage  value="resources/images/syscon/assembly.png"  />
                            <br/>
                            <h:outputText  value="Assemblies"/>
                        </div>
                    </h:commandLink>

                    <h:commandLink action="/genBank/List" immediate="true"  >
                        <div class="menu_item">
                            <h:graphicImage  value="resources/images/syscon/genbank.png"  />
                            <br/>
                            <h:outputText  value="GenBanks"/>
                        </div>
                    </h:commandLink>

                    <h:commandLink action="/fasta/List" immediate="true"  >
                        <div class="menu_item">
                            <h:graphicImage  value="resources/images/syscon/fasta.png"  />
                            <br/>
                            <h:outputText  value="Fastas"/>
                        </div>
                    </h:commandLink>

                    <div onclick="utils.show();"  class="menu_item">
                        <h:graphicImage  value="resources/images/syscon/set.png"  />
                        <br/>
                        <h:outputText  value="Util"/>
                    </div>
                </c:if>

                <div onclick="ctrl_panel.show();"  class="menu_item">
                    <h:graphicImage  value="resources/images/syscon/ctrl.png"  />
                    <br/>
                    <h:outputText  value="Control Painel"/>
                </div>

                <h:commandLink action="#{userController.logout}" immediate="true"  >
                    <div class="menu_item">
                        <h:graphicImage  value="resources/images/syscon/logout_icon.png"  />
                        <br/>
                        <h:outputText  value="Exit"/>
                    </div>
                </h:commandLink>

                <p:dialog  header="User Administration" widgetVar="dlg1" width="300"  height="100" resizable="false" minWidth="600" position="center" >
                    <h:commandLink  action="/user/List"   title="#{userController.users.size()} Users" >
                        <div class="menu_item">
                            <h:graphicImage  value="resources/images/syscon/user_one.png"  />
                            <br/>
                            <h:outputText  value="User Control"/>
                        </div>
                    </h:commandLink>
                    <c:if test="#{userController.allowedGroups('1')}">
                        <h:commandLink  action="/userGroup/List"  title="#{userGroupController.usersGroups.size()} Groups">
                            <div class="menu_item">
                                <h:graphicImage  value="resources/images/syscon/user_group.png"   />
                                <br/>
                                <h:outputText  value="Group Control"/>
                            </div>
                        </h:commandLink>
                    </c:if>
                </p:dialog>
                <p:dialog  header="Utils" widgetVar="utils" width="400"  height="100" resizable="false" minWidth="600" position="center" >
                    <div onclick="jmold.show();"  class="menu_item">
                        <h:graphicImage  value="resources/images/syscon/set.png"  />
                        <br/>
                        <h:outputText  value="JMol"/>
                    </div>
                    <div onclick="jalview.show();"  class="menu_item">
                        <h:graphicImage  value="resources/images/syscon/set.png"  />
                        <br/>
                        <h:outputText  value="JalView"/>
                    </div>
                </p:dialog>
                <p:dialog  header="Control Panel" widgetVar="ctrl_panel" width="400"  height="100" resizable="false" minWidth="600" position="center" >
                    <c:if test="#{userController.allowedGroups('1')}">
                        <h:commandLink  action="/status/List"  title="#{statusController.items.size()} Statuses">
                            <div class="menu_item">
                                <h:graphicImage  value="resources/images/syscon/ctrl.png"   />
                                <br/>
                                <h:outputText  value="Status"/>
                            </div>
                        </h:commandLink>
                    </c:if>
                    <h:commandLink  action="#{userController.prepareViewProfile()}"  title="Personal Info">
                        <div class="menu_item">
                            <h:graphicImage  value="resources/images/syscon/user_one.png"   />
                            <br/>
                            <h:outputText  value="Profile"/>
                        </div>
                    </h:commandLink>
                </p:dialog>


                <p:dialog header="Projects" widgetVar="dlg2"  width="400"  height="100" resizable="false" minWidth="600" position="center" >
                    <h:commandLink  action="${projectController.prepareCreate}"  >
                        <div class="menu_item">
                            <h:graphicImage  value="resources/images/syscon/new_proj.png"  title="#{projectController.items.size() } Projects"/>
                            <br/>
                            <h:outputText  value="New Project"/>
                        </div>
                    </h:commandLink>
                </p:dialog>

            </p:panel>
            <c:if test="#{userController.allowedGroups('2,4')}">
                <p:panel header="All Projects"  styleClass="form"   rendered="#{not empty projectController.items}" toggleable="true" collapsed="false" closeSpeed="100" >
                    <p:dataGrid id="existentProjects" var="proj" value="#{projectController.items}" style="display:inline;"
                                rowIndexVar="current"  >
                        <center>
                            <p:column>
                                <h:commandLink id="proj" action="#{projectController.prepareView()}"  title="#{userGroupController.usersGroups.size()} Groups" >
                                    <f:setPropertyActionListener target="#{projectController.current}" value="#{proj}"/>
                                    <h:graphicImage  value="/resources/images/syscon/proj_bad.png"  >
                                        <p:tooltip for="proj" styleClass="tooltip" >
                                            <h:outputText value="Description: " styleClass="label" />
                                            <h:outputText value="#{proj.prjDesc}"  />
                                            <br/>
                                            <h:outputText value="Created By: "  styleClass="label"/>
                                            <h:outputText value="#{proj.createdBy.userLogin}"  />.
                                            <br/>
                                            <h:outputText value="Created In: "  styleClass="label"/>
                                            <h:outputText value="#{proj.prjCreation}"  />
                                        </p:tooltip>
                                    </h:graphicImage>
                                    <br/>
                                    <h:outputText value="#{proj.prjName}" styleClass="button" />
                                </h:commandLink>
                                <p:contextMenu for="proj" >
                                    <p:menuitem value="View" icon="ui-icon-search" action="#{projectController.prepareView()}">
                                        <f:setPropertyActionListener target="#{projectController.current}" value="#{proj}"/>
                                    </p:menuitem>
                                </p:contextMenu>
                            </p:column>
                        </center>
                    </p:dataGrid>
                </p:panel>
            </c:if>
            <c:if test="#{userController.allowedGroups('2,3')}">
                <p:panel id="projects" header="Assigned Projects "  styleClass="form" rendered="#{not empty userController.assignedProjects}">
                    <p:dataGrid id="assignedProjects" var="proj"  style="display:inline;"
                                value="#{userController.assignedProjects}"
                                rowIndexVar="current">
                        <center>
                            <p:column >
                                <h:commandLink id="proj"  action="#{projectController.prepareView()}"  >
                                    <f:setPropertyActionListener target="#{projectController.current}" value="#{proj}"/>
                                    <p:graphicImage value="/resources/images/syscon/proj_bad.png" >
                                        <p:tooltip for="proj">
                                            <h:outputText value="Description: " styleClass="label" />
                                            <h:outputText value="#{proj.prjDesc}"  />
                                            <br/>
                                            <h:outputText value="Created By: "  styleClass="label"/>
                                            <h:outputText value="#{proj.createdBy.userLogin}"  />.
                                            <br/>
                                            <h:outputText value="Created In: "  styleClass="label"/>
                                            <h:outputText value="#{proj.prjCreation}"  />
                                        </p:tooltip>
                                    </p:graphicImage>
                                    <br/>
                                    <h:outputText value="#{proj.prjName}"  styleClass="button"/>
                                </h:commandLink>
                            </p:column>
                        </center>
                    </p:dataGrid>
                </p:panel>

                <p:panel id="stats" header="System Properties"   collapsed="true" toggleable="true" styleClass="form">
                    <p:dataList value="#{serverController.info.keySet().toArray()}" var="key" styleClass="annotation">
                        <p:column>
                            <h:outputText value="#{key}" styleClass="label"/>
                        </p:column>
                        <h:outputText value="="/>
                        <p:column>
                            <h:outputText value="#{serverController.info.get(key)}"/>
                        </p:column>
                        <br/>
                    </p:dataList>
                </p:panel>
                <p:panel id="jvm_stats" header="JVM Stats"  collapsed="true" toggleable="true" styleClass="form">
                    <h:form id="form">
                        <p:poll interval="3" update="votes" />
                        <p:pieChart id="votes" value="#{serverController.pieModel}"  showDataLabels="true"
                                    legendPosition="nw" style="width:400px;height:300px"/>
                        <p:poll interval="3" update="stats" />
                        <p:lineChart id="stats" value="#{serverController.lineModel}" showMarkers="true" minY="0" maxY="10"
                                     legendPosition="nw" style="width:80%;height:300px"/>
                    </h:form>
                </p:panel>
            </c:if>
        </h:form>
        <div class="form">
            <center>

            </center>
        </div>
    </ui:define>
</ui:composition>



